﻿using System;
using System.Windows.Forms;
using ShadeTree.Binding.Elements;

namespace ShadeTree.Binding.Configuration
{
    public class RadioGroupExpression<ENUM>
    {
        private readonly IScreenBinder _binder;
        private readonly RadioButtonGroup<ENUM> _group = new RadioButtonGroup<ENUM>();
        private readonly Accessor _Accessor;
        private RadioElement<ENUM> _lastElement;

        public RadioGroupExpression(Accessor accessor, IScreenBinder binder)
        {
            _Accessor = accessor;
            _binder = binder;
        }

        public RadioGroupExpression<ENUM> RadioButton(RadioButton button)
        {
            var element = new RadioElement<ENUM>(_Accessor, button, _group);
            _binder.AddElement(element);

            _lastElement = element;

            return this;
        }

        public RadioGroupExpression<ENUM> IsBoundTo(ENUM enumValue)
        {
            _lastElement.BoundValue = enumValue;
            return this;
        }

        public RadioGroupExpression<ENUM> AliasAs(string alias)
        {
            _lastElement.Alias = alias;
            return this;
        }

        public RadioGroupExpression<ENUM> OnClick(Action handler)
        {
            _lastElement.RegisterOnClickHandler(handler);
            return this;
        }

        public RadioGroupExpression<ENUM> RebindAllOnChange()
        {
            _lastElement.RebindAllOnChange();
            return this;
        }
    }
}